<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/8/22 0022
 * Time: 下午 4:16
 */

namespace Company\Controller;

use Think\Controller;

class MemberController extends Controller
{

    public function getMember(){

        //  获取数据库会员信息
        $member=D("member");
        $re=$member->select();
        $this->assign("list",$re);
        $this->display();

    }

    public function addMember(){

        //  接收表单数据
        $psw=$_POST["psww"];
        $member["user"]=$_POST["name"];
        $member["psw"]=$_POST["psw"];
        $member["email"]=$_POST["email"];
        //  校验表单数据格式是否正确
        $mem=D("member");

        //  添加到数据库

        if($member["user"]!=null & $member["psw"]!=null & $member["email"]!=null){
            if($psw===$member["psw"]){
                $re=$mem->add($member);
                echo "会员添加成功";

                $this->success();
            }else{
                echo "两次密码输入不一致";
                $this->error();
            }
        }else{
            echo "信息不能留空";
            $this->error();
        }

    }


    public function deleteMember(){

        //  获取该会员id
        $id=$_GET["id"];
        //  根据id删除该行表格数据
        $delete=D("member");
        $de= $delete->execute("delete from ds_member where id='$id'");
        if(!empty($de)){
            $this->success('删除成功','/member/getMember');
        }
        else{
            $this->error('删除失败','/member/getMember');
        }
    }

}